package ch.bfh.abcmmh.view.fullview.scopepanel;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class ScopeMouseDraggerListener extends MouseAdapter{

	private ScopePanel scopePanel;
	private int mousePredssedX, newScopeX;

	public ScopeMouseDraggerListener(ScopePanel scopePanel) {
		this.scopePanel = scopePanel;
	}

	@Override
	public void mousePressed(MouseEvent e) {
		this.mousePredssedX = e.getX();
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		int movedMouseX = e.getX();
		this.newScopeX = (int) this.scopePanel.getLocation().getX()
				+ movedMouseX - mousePredssedX;
		if (newScopeX >= 0
				&& newScopeX < (scopePanel.getGuiController().getWidth() - scopePanel
						.getScopeWidth())) {
			scopePanel.setLocation(newScopeX, 0);
			scopePanel.calculateStreetArrayPositionofScope();
			scopePanel.updateScopePanel();
		}


	}

}
